#ifndef CORE_H
#define CORE_H

#include "IQueryManager.h"
#include "Client/ClientThread.h"
#include "Log/ILogManager.h"
#include "State/AppState.h"

#include <QObject>
#include <QTimer>

namespace Transport {
class TransportManager;
}

namespace Common {

class QueryManager;

class Core : public QObject
{
	Q_OBJECT
public:
	Core(QObject* parent = 0);

public:
	void openConnection(QString ip, int port);
	void closeConnection();
	ClientThread* transport(){return _transport;}
	Log::ILogManager* logManager(){return _logManager;}
	void setLogManager(Log::ILogManager* log){_logManager = log;}
	void addLogMsg(QString msg, Log::ILogManager::LogType type = Log::ILogManager::INFO);
	State::AppState state(){return _state;}

public slots:
	void addCommand(Common::ICommand::SPtr command);

private slots:
	void onMessageRecieved(QByteArray data);
	void onConnected();
	void onDisconnected();
	void onConnectionError(QString err);

signals:
	void connected();
	void disconnected();

private:
	void processMessage(QByteArray data);

private:
	QueryManager*		_queryManager;
	ClientThread*		_transport;
	Log::ILogManager*	_logManager;
	State::AppState		_state;
};

}

#endif // CORE_H
